#include "sms.h"
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <fcntl.h>


#define TOP_LIST_LAYOUT_NAME "layout-teacher-top"


typedef struct _Title{
	gdouble icon_x;
	gdouble icon_y;
	gdouble top_x;
	gdouble top_y;
	gdouble right_x;
	gdouble right_y;
	gdouble left_x;
	gdouble left_y;
	char *font;
	char *colour;
	GooCanvasItem *icon;
	GooCanvasItem *top_text;
	GooCanvasItem *right_text;
	GooCanvasItem *left_text;
}Title;


typedef struct _Page_Controller{
	gdouble page_up_x;
	gdouble page_up_y;
	gdouble text_x;
	gdouble text_y;
	gdouble page_down_x;
	gdouble page_down_y;
	GooCanvasItem *page_up;
	GooCanvasItem *page_down;
  GooCanvasItem *text;
}Page_Controller;

typedef struct _List_Text
{
	GdkPixbuf *icon;
	char *dir;
	char *text;
	char *layout;
	char *layout_xml_path;
}List_Text;


typedef struct _TOP_LIST_LAYOUT
{
	GooCanvasItem *bg;
	GooCanvasItem *text_bg;
	GooCanvasItem *tip_bg;
	GooCanvasItem *right_list_bg;
	GooCanvasItem *progress_bar;
	GooCanvasItem *arrow;
	GooCanvasItem *icon;
	GooCanvasItem *icon_text;

	int selected_list;

	GooCanvasItem *text;
	Downloader *downloader;

	SListView *left_list_view;
	SListView *right_list_view;
	int left_list_text_sum;
	int right_list_text_sum;
  List_Text **left_list_text;
  List_Text **right_list_text;

  int right_list_cur_page;
  int right_list_total_page;

	Title title;
	Page_Controller page_controller;
}Top_List_Layout;

gboolean top_wait = FALSE;//this is a tag for all listview load finish


static gboolean top_list_layout_load_config(Layout *layout, char *conf_file, gboolean (* travel_xml)(xmlNode *, Layout *)){
	printf("start func %s\n" ,__FUNCTION__);
	Top_List_Layout  *top_list_layout = layout->private;
	SMS *sms=layout->sms;

	gboolean ret=FALSE;
	xmlDoc *doc = NULL;
	xmlNode *root_element = NULL;


	doc = xmlReadFile(conf_file, NULL, 0);

	if (doc == NULL) {
		fprintf(stderr,"error: could not parse file %s\n", conf_file);
		return ret;
	}

	root_element = xmlDocGetRootElement(doc);

	if(root_element){
		xmlNode *cur_node = NULL;
		for (cur_node = root_element; cur_node; cur_node = cur_node->next) {
			if (cur_node->type == XML_ELEMENT_NODE) {
				ret=TRUE;
				break;
			}
		}
		if(ret) {
			//ret=video_list_layout_travel_xml(cur_node->children,layout);
			ret = travel_xml(cur_node->children, layout);
		}
	}

	xmlFreeDoc(doc);
	xmlCleanupParser();
	top_wait=TRUE;
	printf("finish func %s\n" ,__FUNCTION__);
	return ret;
}


static gboolean top_list_layout_load_bg(xmlNode *a_node, Layout *layout)
{
	printf("start func %s\n" ,__FUNCTION__);
	Top_List_Layout  *top_list_layout = layout->private;
	GdkPixbuf*  pixbuf_bg, *pixbuf_text_bg ,*pixbuf_tip_bg;
	xmlChar * val;
	gdouble textbg_x, textbg_y ,tip_x ,tip_y;
	char pic[256];

	if(top_list_layout->bg||!a_node)
		return FALSE;

	val = xmlGetProp (a_node,(xmlChar*)"pic");
	if(!val)
		return FALSE;

	sprintf(pic,"%s/%s/layout/%s/%s",SMS_RESOURCE_DIR,"default"/*theme*/,layout->name,val);
	printf("pic=%s\n" , pic);
	pixbuf_bg = sms_load_pic(pic,800,480);
	if(!pixbuf_bg)
		return FALSE;

	top_list_layout->bg=goo_canvas_image_new (layout->cavas, pixbuf_bg, 0, 0, NULL);


	textbg_x = sms_get_xml_double (a_node, (xmlChar*)"textbg_x", 37);
	textbg_y = sms_get_xml_double (a_node, (xmlChar*)"textbg_y", 66);

	val = xmlGetProp (a_node,(xmlChar*)"text_bg");
	if(!val)
		return FALSE;
	
	sprintf(pic,"%s/%s/layout/%s/%s",SMS_RESOURCE_DIR,"default"/*theme*/,layout->name,val);
	printf("pic=%s\n", pic);
	pixbuf_text_bg = gdk_pixbuf_new_from_file(pic, NULL);
	top_list_layout->text_bg = goo_canvas_image_new (layout->cavas, pixbuf_text_bg, textbg_x, textbg_y, NULL);

	tip_x = sms_get_xml_double (a_node, (xmlChar*)"tip_x", 0);
	tip_y = sms_get_xml_double (a_node, (xmlChar*)"tip_y", 371);

	val = xmlGetProp (a_node,(xmlChar*)"tip_bg");
	if(!val)
		return FALSE;

	sprintf(pic,"%s/%s/layout/%s/%s",SMS_RESOURCE_DIR,"default"/*theme*/,layout->name,val);
	printf("pic=%s\n", pic);
	pixbuf_tip_bg = gdk_pixbuf_new_from_file(pic, NULL);
	top_list_layout->tip_bg = goo_canvas_image_new (layout->cavas, pixbuf_tip_bg, tip_x, tip_y, NULL);

	g_object_unref (G_OBJECT (pixbuf_bg));
	g_object_unref (G_OBJECT (pixbuf_text_bg));
	g_object_unref (G_OBJECT (pixbuf_tip_bg));
	printf("finish func %s\n" ,__FUNCTION__);

	return TRUE;

}

static gboolean top_list_layout_load_title(xmlNode *a_node, Layout *layout)
{
	printf("start func %s\n" ,__FUNCTION__);

	if(!a_node)
		return FALSE;

	Top_List_Layout  *top_list_layout = layout->private;
	GdkPixbuf*  pixbuf;
	xmlChar *val;
	char pic[256];

	top_list_layout->title.icon_x = sms_get_xml_double (a_node, (xmlChar*)"icon_x", 0);
	top_list_layout->title.icon_y = sms_get_xml_double (a_node, (xmlChar*)"icon_y", 0);
	top_list_layout->title.top_x = sms_get_xml_double (a_node, (xmlChar*)"top_x", 0);
	top_list_layout->title.top_y = sms_get_xml_double (a_node, (xmlChar*)"top_y", 0);
	top_list_layout->title.right_x = sms_get_xml_double (a_node, (xmlChar*)"right_x", 0);
	top_list_layout->title.right_y = sms_get_xml_double (a_node, (xmlChar*)"right_y", 0);
	top_list_layout->title.left_x = sms_get_xml_double (a_node, (xmlChar*)"left_x", 0);
	top_list_layout->title.left_y = sms_get_xml_double (a_node, (xmlChar*)"left_y", 0);

	val = xmlGetProp (a_node, (xmlChar*)"colour");
	

	if(!val) 
	{
		//colour = "black";
		top_list_layout->title.colour = "black";
	} else {
		top_list_layout->title.colour = val;
	}

	val = xmlGetProp (a_node, (xmlChar*)"icon");
	if(!val)
	   	return FALSE;
	sprintf(pic, "%s/%s/layout/%s/%s", SMS_RESOURCE_DIR, "default"/*theme*/, layout->name, val);

	pixbuf = gdk_pixbuf_new_from_file(pic, NULL);
	if(!pixbuf)
	  	return FALSE;
	top_list_layout->title.icon = goo_canvas_image_new (layout->cavas, pixbuf, top_list_layout->title.icon_x,
			                                                                     top_list_layout->title.icon_y, NULL);
	g_object_unref (G_OBJECT (pixbuf));

	val = xmlGetProp (a_node, (xmlChar*)"font");
	if(!val) {
		//font = "Sans 20";
		top_list_layout->title.font = "Sans 20";
	} else {
		top_list_layout->title.font = val;
	}

	val = xmlGetProp (a_node, (xmlChar*)"top_text");
	
	top_list_layout->title.top_text = goo_canvas_text_new(layout->cavas, val, top_list_layout->title.top_x,
			                                                                top_list_layout->title.top_y, 120, GTK_ANCHOR_NW,
			                                                                  "font", top_list_layout->title.font,//introduction_layout->title.font,
			                                                                  "fill-color", top_list_layout->title.colour,
			                                                                  "ellipsize", PANGO_ELLIPSIZE_END,
			                                                                  "alignment", PANGO_ALIGN_LEFT, NULL);

	val = xmlGetProp (a_node, (xmlChar*)"left_text");
	top_list_layout->title.left_text = goo_canvas_text_new(layout->cavas,"名\n师\n排\n行" ,top_list_layout->title.left_x,
																																	top_list_layout->title.left_y,120,GTK_ANCHOR_NW,
																																	"font" ,"Sans 15",
																																	"fill-color", top_list_layout->title.colour,
			                                                                  "ellipsize", PANGO_ELLIPSIZE_END,
			                                                                  "alignment", PANGO_ALIGN_LEFT, NULL);				

	val = xmlGetProp (a_node, (xmlChar*)"right_text");
	top_list_layout->title.right_text = goo_canvas_text_new(layout->cavas,"热\n门\n课\n堂" ,top_list_layout->title.right_x,
																																	top_list_layout->title.right_y,120,GTK_ANCHOR_NW,
																																	"font" ,"Sans 15",
																																	"fill-color", top_list_layout->title.colour,
			                                                                  "ellipsize", PANGO_ELLIPSIZE_END,
			                                                                  "alignment", PANGO_ALIGN_LEFT, NULL);					

	return TRUE;
}

static gboolean top_list_layout_load_list_resource(xmlNode *a_node, Layout *layout,
		                                         int *list_x, int *list_y,
		                                         int *item_border, int *item_height,
		                                         int *view_count, int *list_width,
		                                         GdkPixbuf **pixbuf_item_icon, GdkPixbuf **pixbuf_item_fg,
		                                         GdkPixbuf **pixbuf_down_btn, GdkPixbuf **pixbuf_up_btn)
{
	printf("start func %s\n" ,__FUNCTION__);
	xmlChar *val;
	char pic[256];

	*list_x = sms_get_xml_int (a_node, (xmlChar*)"x", 0);
	*list_y = sms_get_xml_int (a_node, (xmlChar*)"y", 0);
	*item_border = sms_get_xml_int (a_node, (xmlChar*)"item_border", 0);
	*view_count = sms_get_xml_int (a_node, (xmlChar*)"view_count", 0);


	

	val = xmlGetProp (a_node, (xmlChar*)"item_icon");
	if(!val)
	   	return FALSE;
	sprintf(pic, "%s/%s/layout/%s/%s", SMS_RESOURCE_DIR, "default"/*theme*/, layout->name, val);
	printf("pic: %s\n", pic);
	*pixbuf_item_icon = gdk_pixbuf_new_from_file(pic, NULL);

	val = xmlGetProp (a_node, (xmlChar*)"item_fg");
	if(!val)
	   	return FALSE;
	sprintf(pic, "%s/%s/layout/%s/%s", SMS_RESOURCE_DIR, "default"/*theme*/, layout->name, val);
	printf("pic: %s\n", pic);
	*pixbuf_item_fg = gdk_pixbuf_new_from_file(pic, NULL);
	*item_height = gdk_pixbuf_get_height (*pixbuf_item_fg);
	*list_width = gdk_pixbuf_get_width (*pixbuf_item_fg);

	val = xmlGetProp (a_node, (xmlChar*)"down_btn");
	if(!val)
	  	return FALSE;
	sprintf(pic, "%s/%s/layout/%s/%s", SMS_RESOURCE_DIR, "default"/*theme*/, layout->name, val);
	printf("pic: %s\n", pic);
	*pixbuf_down_btn = gdk_pixbuf_new_from_file(pic, NULL);

	val = xmlGetProp (a_node, (xmlChar*)"up_btn");
	if(!val)
	   	return FALSE;
	sprintf(pic, "%s/%s/layout/%s/%s", SMS_RESOURCE_DIR, "default"/*theme*/, layout->name, val);
	printf("pic: %s\n", pic);
	*pixbuf_up_btn = gdk_pixbuf_new_from_file(pic, NULL);

	return TRUE;
}

static gboolean top_list_layout_load_list_text(xmlNode *a_node, Layout *layout, int text_sum, int leftOrRight)
{
	printf("start func %s\n" ,__FUNCTION__);
	xmlNode *text_node = a_node;
	Top_List_Layout  *top_list_layout = layout->private;
	xmlChar *val;

	int i = 0;
	for (text_node; text_node; text_node = text_node->next) {
			if (text_node->type == XML_ELEMENT_NODE) {
				printf("node type: Element, name: %s\n", text_node->name);
				if(strcmp(text_node->name, "item")==0) {
					if (leftOrRight == 0) {
						top_list_layout->left_list_text[i] = (List_Text *) g_malloc0(sizeof(List_Text) + 1);
						top_list_layout->left_list_text[i]->dir =  xmlGetProp (text_node, (xmlChar*)"dir");
						top_list_layout->left_list_text[i]->text = xmlGetProp (text_node, (xmlChar*)"value");
					    top_list_layout->left_list_text[i]->layout = xmlGetProp (text_node, (xmlChar*)"layout");
					    top_list_layout->left_list_text[i]->layout_xml_path = xmlGetProp (text_node, (xmlChar*)"layout_xml_path");
					    printf("text: %s, layout: %s \ndir: %s \nxml_path: %s \n", top_list_layout->left_list_text[i]->text,
							                                           top_list_layout->left_list_text[i]->layout,
							                                           top_list_layout->left_list_text[i]->dir,
							                                           top_list_layout->left_list_text[i]->layout_xml_path);
					} else if (leftOrRight == 1) {
						top_list_layout->right_list_text[i] = (List_Text *) g_malloc0(sizeof(List_Text) + 1);
						top_list_layout->right_list_text[i]->dir =  xmlGetProp (text_node, (xmlChar*)"dir");
						top_list_layout->right_list_text[i]->text = xmlGetProp (text_node, (xmlChar*)"value");
						top_list_layout->right_list_text[i]->layout = xmlGetProp (text_node, (xmlChar*)"layout");
						top_list_layout->right_list_text[i]->layout_xml_path = xmlGetProp (text_node, (xmlChar*)"layout_xml_path");
						printf("text: %s, layout: %s \n  dir: %s \nxml_path: %s \n", top_list_layout->right_list_text[i]->text,
								                                           top_list_layout->right_list_text[i]->layout,
								                                           top_list_layout->right_list_text[i]->dir,
								                                           top_list_layout->right_list_text[i]->layout_xml_path);
					}
					++i;
				}
			}
	}

	return TRUE;
}


static SListIter *top_list_layout_create_left_list_iter(Top_List_Layout  *top_list_layout, const char *text, GdkPixbuf *pixbuf_icon)
{
	printf("start func %s\n" ,__FUNCTION__);
	SListView *view=top_list_layout->left_list_view;
	SListIter *iter;
	
	iter=view->method->slistmethod_create_iter(view, "icon", pixbuf_icon, "text", text, NULL);	
	//g_object_unref(pixbuf_icon);
	return iter;
	
}

static gboolean top_list_layout_load_left_list(xmlNode *a_node, Layout *layout)
{
	printf("start func %s\n" ,__FUNCTION__);
	SMS *sms=layout->sms;
	Top_List_Layout  *top_list_layout = layout->private;
	xmlNode *cur_node = a_node->children;
	//xmlChar *val;
	gboolean ret;
	int i;

	GdkPixbuf *pixbuf_item_icon, *pixbuf_item_fg, //*pixbuf_item_bg,
	          *pixbuf_down_btn, *pixbuf_up_btn;

	int list_x, list_y, item_border, view_count, list_width, item_height;

	ret = top_list_layout_load_list_resource(a_node, layout, &list_x, &list_y, 
																				&item_border, &item_height, 
																				&view_count, &list_width,
			                                      &pixbuf_item_icon, &pixbuf_item_fg,
				                                   &pixbuf_down_btn, &pixbuf_up_btn);


	printf("x=%d ,y=%d ,border=%d ,height=%d, count=%d ,width=%d \n" ,
														list_x ,list_y ,item_border ,item_height ,view_count ,list_width);
	for (cur_node; cur_node; cur_node = cur_node->next) {
		if (cur_node->type == XML_ELEMENT_NODE) {
			printf("node type: Element, name: %s\n", cur_node->name);
			if(strcmp(cur_node->name, "items")==0) {
			    printf("ready to load texts\n");
					top_list_layout->left_list_text_sum = sms_get_xml_int (cur_node, (xmlChar*)"sum", 0);
		       top_list_layout->left_list_text = (List_Text **) g_malloc0(sizeof(List_Text *)*top_list_layout->left_list_text_sum + 1);
		       top_list_layout_load_list_text(cur_node->children, layout, top_list_layout->left_list_text_sum, 0);
			}
		}
	}

	//video_list_layout_load_list_by_page(layout, 0, 1, TRUE);
	printf("ret = %d\n" ,ret);
	if(!ret)
		return FALSE;

	top_list_layout->left_list_view = slistview_new(layout->cavas, list_x, list_y, list_width, item_height,
			                                                         item_border, view_count, sms->theme);
	slistview_set_pic(top_list_layout->left_list_view,NULL, pixbuf_item_fg, pixbuf_up_btn, pixbuf_down_btn);
	
	for (i=0; i<top_list_layout->left_list_text_sum; i++)
	{
		slistview_append_iter(top_list_layout->left_list_view,
		top_list_layout_create_left_list_iter(top_list_layout, top_list_layout->left_list_text[i]->text, pixbuf_item_icon));
	}
	
	slistview_show(top_list_layout->left_list_view);
	top_list_layout->selected_list = 0;

	g_object_unref (G_OBJECT (pixbuf_item_fg));
	g_object_unref (G_OBJECT (pixbuf_up_btn));
	g_object_unref (G_OBJECT (pixbuf_down_btn));
	g_object_unref (G_OBJECT (pixbuf_item_icon));

	return TRUE;
}


static SListIter *top_list_layout_create_right_list_iter(Top_List_Layout *top_list_layout, const char *text, GdkPixbuf *pixbuf_icon)
{
	printf("start func %s\n" ,__FUNCTION__);
	SListView *view=top_list_layout->right_list_view;
	SListIter *iter;

	iter=view->method->slistmethod_create_iter(view, "icon", pixbuf_icon, "text", text, NULL);
	//g_object_unref(pixbuf_icon);
	return iter;

}

static gboolean top_list_layout_load_right_list(xmlNode *a_node, Layout *layout)
{
	printf("start func %s\n" ,__FUNCTION__);
	SMS *sms=layout->sms;
	Top_List_Layout  *top_list_layout = layout->private;
	xmlNode *cur_node = a_node->children;
	//xmlChar *val;
	gboolean ret;
	int i;

	GdkPixbuf *pixbuf_item_icon, *pixbuf_item_fg, //*pixbuf_item_bg,
	          *pixbuf_down_btn, *pixbuf_up_btn;

	int list_x, list_y, item_border, view_count, list_width, item_height;

	ret = top_list_layout_load_list_resource(a_node, layout, &list_x, &list_y, 
																				&item_border, &item_height, 
																				&view_count, &list_width,
			                                      &pixbuf_item_icon, &pixbuf_item_fg,
				                                   &pixbuf_down_btn, &pixbuf_up_btn);


	printf("x=%d ,y=%d ,border=%d ,height=%d, count=%d ,width=%d \n" ,
														list_x ,list_y ,item_border ,item_height ,view_count ,list_width);
	for (cur_node; cur_node; cur_node = cur_node->next) {
		if (cur_node->type == XML_ELEMENT_NODE) {
			printf("node type: Element, name: %s\n", cur_node->name);
			if(strcmp(cur_node->name, "items")==0) {
			    printf("ready to load texts\n");
					top_list_layout->right_list_text_sum = sms_get_xml_int (cur_node, (xmlChar*)"sum", 0);
		       top_list_layout->right_list_text = (List_Text **) g_malloc0(sizeof(List_Text *)*top_list_layout->right_list_text_sum + 1);
		       ret &= top_list_layout_load_list_text(cur_node->children, layout, top_list_layout->right_list_text_sum, 1);
			}
		}
	}

	//video_list_layout_load_list_by_page(layout, 0, 1, TRUE);
	printf("start func %s ,ret = %d\n" ,__FUNCTION__ ,ret);
	if(!ret)
		return FALSE;

	top_list_layout->right_list_view = slistview_new(layout->cavas, list_x, list_y, list_width, item_height,
			                                                         item_border, view_count, sms->theme);
	slistview_set_pic(top_list_layout->right_list_view,NULL, pixbuf_item_fg, pixbuf_up_btn, pixbuf_down_btn);
	
	for (i=0; i<top_list_layout->right_list_text_sum; i++)
	{
		slistview_append_iter(top_list_layout->right_list_view,
		top_list_layout_create_right_list_iter(top_list_layout, top_list_layout->right_list_text[i]->text, pixbuf_item_icon));
	}
	
	slistview_show(top_list_layout->right_list_view);
	SListView *view= top_list_layout->right_list_view;
	g_object_set(view->highlight,"visibility",GOO_CANVAS_ITEM_HIDDEN,NULL);

	g_object_unref (G_OBJECT (pixbuf_item_fg));
	g_object_unref (G_OBJECT (pixbuf_up_btn));
	g_object_unref (G_OBJECT (pixbuf_down_btn));
	g_object_unref (G_OBJECT (pixbuf_item_icon));

	return TRUE;
}



static gboolean top_list_layout_travel_xml(xmlNode *a_node,Layout *layout)
{
	printf("start func %s\n" ,__FUNCTION__);
	Top_List_Layout  *top_list_layout = layout->private;
	SMS *sms=layout->sms;
	xmlChar *val;
	char pic[256];
	xmlNode *cur_node = NULL;
	xmlNode *bg_node = NULL;
	//xmlNode *animate_node = NULL;
	xmlNode *title_node = NULL;
	xmlNode *left_list_node = NULL;
	xmlNode *right_list_node = NULL;
	xmlNode *page_control_node = NULL;

	for (cur_node = a_node; cur_node; cur_node = cur_node->next) {
		if (cur_node->type == XML_ELEMENT_NODE) {
			printf("node type: Element, name: %s\n", cur_node->name);
			if(strcmp(cur_node->name,"bg")==0)
				bg_node=cur_node;
			else if(strcmp(cur_node->name,"title")==0)
				title_node = cur_node;
			else if(strcmp(cur_node->name,"left-list")==0)
				left_list_node = cur_node;
			else if(strcmp(cur_node->name,"right-list")==0)
				right_list_node = cur_node;
			/*else if(strcmp(cur_node->name,"animates")==0)
				animate_node = cur_node;
		  else if(strcmp(cur_node->name,"page-control")==0) {
		    	page_control_node = cur_node;
		    }*/
		}
	}

		if(!bg_node ||!title_node||!left_list_node||!right_list_node)
			return FALSE;

		top_list_layout_load_bg(bg_node,layout);
		top_list_layout_load_title(title_node, layout);
		//top_list_layout_load_page_controller(page_control_node, layout);
		top_list_layout_load_left_list(left_list_node, layout);

		top_list_layout_load_right_list(right_list_node, layout);
		//teacher_style_layout_load_animates (animate_node->children, layout);

	printf("finish func %s\n" ,__FUNCTION__);
	return TRUE;
}

gboolean top_list_layout_key_press(Layout * layout,GdkEventKey *event) 
{
	printf("start func %s\n" ,__FUNCTION__);
	Top_List_Layout  *top_list_layout = layout->private;
	if(top_wait){
		if (event->keyval==GDK_Escape){
			sms_change_win_to(layout->sms,LAYOUT_WIN_TEACHER);
			return TRUE ;
		}
		else if (event->keyval==GDK_Up){
			if(top_list_layout->selected_list == 0)
				slistview_scroll(top_list_layout->left_list_view, -1);
			else
				slistview_scroll(top_list_layout->right_list_view, -1);
			return TRUE;
		}
		else if (event->keyval==GDK_Down){
			if(top_list_layout->selected_list == 0)
				slistview_scroll(top_list_layout->left_list_view, 1);
			else
				slistview_scroll(top_list_layout->right_list_view, 1);
			return TRUE;
		}
		else if (event->keyval==GDK_Left){
			if(top_list_layout->selected_list == 1)
			{
				top_list_layout->selected_list = 0;
				slistview_set_active(top_list_layout->left_list_view, TRUE);
				slistview_set_active(top_list_layout->right_list_view, FALSE);
			}
			return TRUE;
		}
		else if (event->keyval==GDK_Right){
			if(top_list_layout->selected_list == 0)
			{
				top_list_layout->selected_list = 1;
				slistview_set_active(top_list_layout->left_list_view, FALSE);
				slistview_set_active(top_list_layout->right_list_view, TRUE);
			}
			return TRUE;
		}
		else if (event->keyval == GDK_Return){
			//printf("list select = %d ,text=%s\n" ,top_list_layout->selected_list ,top_list_layout->left_list_text[i]->text);
		}
	}

	return FALSE ;
}


gboolean top_list_layout_init(Layout *layout,gpointer data)
{
	printf("start func %s\n" ,__FUNCTION__);
	printf("layout property xml path : %s\n", layout->layout_property.xml_path);

	SMS *sms=layout->sms;
	GdkPixbuf *pixbuf;
	char conf[256];

	Top_List_Layout  *top_list_layout=(Top_List_Layout *)g_malloc0(sizeof(Top_List_Layout)+1);

	layout->private=(void *)top_list_layout;

	layout->cavas = goo_canvas_group_new(layout->parent,NULL);

	/*hjq add */
	if (layout->layout_property.xml_path) 
	{
		strcpy(conf, layout->layout_property.xml_path);
	}else
	{
		sprintf(conf, "%s/%s/layout/%s/layout.xml", SMS_RESOURCE_DIR, 
													"default", layout->name);
	}
	printf("conf: %s\n", conf);
	/**/

	if(!top_list_layout_load_config(layout, conf, &top_list_layout_travel_xml)){
		fprintf(stderr,"%s:load config err\n",__FUNCTION__);
		return FALSE;//exit(-1);
	}

	//video_list_layout->in_left=TRUE;

	printf("finish func %s\n" ,__FUNCTION__);
	return TRUE;
}


Layout *top_list_layout_new(GooCanvasItem * parent,gpointer sms)
{
	Layout *layout=layout_new(parent, LAYOUT_TYPE_WIN, LAYOUT_WIN_TOP_LIST, 
																								TOP_LIST_LAYOUT_NAME, sms);
	layout_set_func(layout,"init", top_list_layout_init);
	//layout_set_func(layout,"clear", top_list_layout_clear);
	layout_set_func(layout,"key-press", top_list_layout_key_press);

	return layout;
}


